using BuildingBlocks.Abstractions.Permissions;
using Identity.Application.PermissionKeyResourceIds.Interfaces;
using Identity.Application.PermissionKeyResourceIds.Queries;
using MediatR;

namespace Identity.Application.PermissionKeyResourceIds.QueryHandlers
{
    public class GetPermissionKeyResourceIdFromServiceNameQueryHandler : IRequestHandler<GetPermissionKeyResourceIdFromServiceNameQuery, List<PermissionBindingDto>>
    {
        private readonly IApiPermissionBindingReadService _permissionKeyResourceIdReadService;
        public GetPermissionKeyResourceIdFromServiceNameQueryHandler(IApiPermissionBindingReadService permissionKeyResourceIdReadService)
        {
             _permissionKeyResourceIdReadService= permissionKeyResourceIdReadService;
        }
        public async Task<List<PermissionBindingDto>> Handle(GetPermissionKeyResourceIdFromServiceNameQuery request, CancellationToken cancellationToken)
        {
            var permissionBinding = await _permissionKeyResourceIdReadService.GetBindingsAsync(request.serviceName, cancellationToken);
            return permissionBinding.ToList();
        }
    }
}